/**
 * $Revision: 1.0 $
 * $Author: Eric Yang $
 * $Date: Jan 15, 2010 12:01:56 AM $
 *
 * Author: Eric Yang
 * Date  : Jan 15, 2010 12:01:56 AM
 *
 */
package com.gooex.web.action.manage.company;

import org.c4j.string.StringTools;

import com.gooex.domain.company.Company;
import com.gooex.service.company.ICompanyManager;
import com.gooex.web.action.BaseManageableAction;


/**
 * @author Eric Yang
 * @version 1.0
 */
public class ManageCompanyOperateAction extends BaseManageableAction {

	private ICompanyManager companyManager;

	private Company company;

	private String target;

	private String id;

	public String save() throws Exception {
		if (company == null) {
			return INPUT;
		}
		if (StringTools.isNotBlankOrNull(company.getId())) {
			// CHECK WHETHER CAN EDIT THE PRODUCT
		}
		companyManager.saveCompany(company);
		id = company.getId();
		if (target != null && ("company".equals(target) || "order".equals(target))) {
			return target;
		}

		return SUCCESS;
	}

	public String authorite() throws Exception {
		Company company = companyManager.getCompany(id);
		if (company != null && isSystemUser()) {
			company.setAccredited(true);
			companyManager.saveCompany(company);
		}
		return SUCCESS;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public void setCompanyManager(ICompanyManager companyManager) {
		this.companyManager = companyManager;
	}

	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}

	public String getId() {
		return id;
	}
}
